package com.asyf.demo.controller;

import com.asyf.demo.service.EasyPoiTemplateService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @Author yjz
 * @Date 2021/8/16 13:59
 * 参考：https://blog.csdn.net/u012441819/article/details/96828044
 * <p>
 * 文档地址：http://doc.wupaas.com/docs/easypoi/easypoi-1c0u6ksp2r091
 * <p>
 * HSSF是POI工程对Excel 97(-2007) (.xls)
 * XSSF是POI工程对Excel 2007 OOXML (.xlsx)
 * <p>
 * 踩坑
 * 1 excel遍历的时候不能出现空单元格，要添加占位符
 */
@RestController
@Api(tags = "easyPoi模板功能测试")
@RequestMapping(value = "/easyPoiTemplate")
@Slf4j
public class EasyPoiTemplateController {

    @Autowired
    private EasyPoiTemplateService service;

    @RequestMapping(value = "export", method = RequestMethod.GET)
    @ApiOperation(value = "模板导出测试")
    @ApiImplicitParams({})
    public void importTest(HttpServletResponse response, HttpServletRequest request) throws Exception {
        service.exportTest(response, request);
    }

    @RequestMapping(value = "foreach", method = RequestMethod.GET)
    @ApiOperation(value = "foreach示例")
    @ApiImplicitParams({})
    public void foreach(HttpServletResponse response, HttpServletRequest request) throws Exception {
        service.foreach(request, response);
    }

    @RequestMapping(value = "foreach2", method = RequestMethod.GET)
    @ApiOperation(value = "foreach示例2")
    @ApiImplicitParams({})
    public void foreach2(HttpServletResponse response, HttpServletRequest request) throws Exception {
        service.foreach2(response, request);
    }

    @RequestMapping(value = "foreach3", method = RequestMethod.GET)
    @ApiOperation(value = "嵌套模板")
    @ApiImplicitParams({})
    public void foreach3(HttpServletResponse response, HttpServletRequest request) throws Exception {
        service.foreach3(request, response);
    }

}
